package com.gitee.wsl.collections.list.iterator

class BufferIterator<out T>(
    private val buffer: Array<T>,
    index: Int,
    size: Int
) : AbstractListIterator<T>(index, size) {
    override fun next(): T {
        if (!hasNext()) {
            throw NoSuchElementException()
        }
        return buffer[index++]
    }

    override fun previous(): T {
        if (!hasPrevious()) {
            throw NoSuchElementException()
        }
        return buffer[--index]
    }
}